/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Interfaces.ApparentModalI;
import Interfaces.Diaxeirish;
import Model.Artist;
import Model.Musicgenre;
import Model.Sex;
import java.awt.Frame;
import static java.awt.event.KeyEvent.VK_ENTER;
import java.text.ParseException;
import java.util.Date;
import javax.swing.JComponent;
import javax.swing.JFrame;
import src.General;
import static src.General.dateFormater;
import src.SimpleDateFormatInputVerifier;
import src.TextMaxLengthTrimInputVerifier;

/**
 * Διαχείριση καλλιτέχνη
 */
public class DiaxeirishKallitexnwnJFrame extends javax.swing.JFrame implements Diaxeirish, ApparentModalI {

    ArtistsArchiveJFrame caller;
    private Artist artist;//για περίπτωση διαχείρισης ActionType.Update παίρνει αντίγραφο του επιλεγμένου γκρουπ του πίνακα της καλούσας φόρμας και δεν γίνεται ποτέ managed. Χρησιμοποιείται η μέθοδος merge του entity manager
    private General.ActionType actionType;
    private final JFrame next = null;

    /**
     * Creates new form DiaxeirishKallitexnwnJFrame
     */
    public DiaxeirishKallitexnwnJFrame() {
        throw new UnsupportedOperationException();
    }

    public DiaxeirishKallitexnwnJFrame(ArtistsArchiveJFrame caller, General.ActionType at)  {
        initComponents();
        try {
            General.setWindowImage(this);
        } catch (Exception ex) {
        }
        this.caller = caller;
        this.artist = this.caller.getSelectedEntityClone();
        this.actionType = at;
        //Ανάλογα με την περίπτωση διαχείρισης
        switch (actionType) {
            case Insert:
                this.setTitle(this.getTitle() + " - " + "Εισαγωγή");
                this.actionJButton.setText("Αποθήκευση");
                this.sexJComboBox.setSelectedIndex(-1);
                this.genreJComboBox.setSelectedIndex(-1);
                break;
            case Update:
                this.setTitle(this.getTitle() + " - " + "Μεταβολή");
                this.actionJButton.setText("Αποθήκευση");
                this.setFormData();
                break;
            case Delete:
                this.setTitle(this.getTitle() + " - " + "Διαγραφή !");
                this.actionJButton.setText("Διαγραφή");
                this.setFormData();
                General.disableAllComponents(this.jPanel1);
                break;
            default:
                break;
        }

        //Θέτει τους InputVerifier για το input του χρήστη
        if (this.actionType != General.ActionType.Delete) {
            this.eponymoJTextField.setInputVerifier(new TextMaxLengthTrimInputVerifier(this.eponymoValidationJLabel, 50));
            this.onomaJTextField.setInputVerifier(new TextMaxLengthTrimInputVerifier(this.onomaValidationJLabel, 50));
            this.kalOnomaJTextField.setInputVerifier(new TextMaxLengthTrimInputVerifier(this.kalOnomaValidationJLabel, 50));
            this.birthPlaceJTextField.setInputVerifier(new TextMaxLengthTrimInputVerifier(this.birthPlaceValidationJLabel, 255));
            this.birthdayJTextField.setInputVerifier(new SimpleDateFormatInputVerifier(this.birthdayValidationJLabel));
        }
    }
    
     @Override
    public void setFormData() {
        eponymoJTextField.setText(this.artist.getLastname());
        onomaJTextField.setText(this.artist.getFirstname());
        kalOnomaJTextField.setText(this.artist.getArtisticName());
        General.selectIndexIfItemToStringEquals(sexJComboBox, this.artist.getSexId().getSexName());
        General.selectIndexIfItemToStringEquals(genreJComboBox, this.artist.getMusicGenreId().getMusicGenreName());
        this.birthdayJTextField.setText(dateFormater.format(this.artist.getBirthday()));
        this.birthPlaceJTextField.setText(this.artist.getBirthPlace());
    }
    
     @Override
    public boolean setEntiyFromFormData() {
        //Θέτει στον artist τις τιμές των πεδίων
        this.artist.setLastname(this.eponymoJTextField.getText());
        this.artist.setFirstname(this.onomaJTextField.getText());
        this.artist.setArtisticName(this.kalOnomaJTextField.getText());
        this.artist.setSexId((Sex) this.sexJComboBox.getSelectedItem());
        this.artist.setBirthPlace(this.birthPlaceJTextField.getText());
        this.artist.setMusicGenreId((Musicgenre) this.genreJComboBox.getSelectedItem());
        try {
            this.artist.setBirthday(dateFormater.parse(this.birthdayJTextField.getText()));
        } catch (ParseException ex) {
            General.showErrorMessage(ex.getMessage(), "Error", this);
            return false;
        }
        if (this.actionType == General.ActionType.Insert) {
            this.artist.setCreatedBy(General.strUserName);
            this.artist.setCreatedDate(new Date());
        }
        return true;
    }

        @Override
    public Frame getCaller() {
        return this.caller;
    }

    @Override
    public Frame getNext() {
        return this.next;
    }

    @Override
    public void setCallersNextNull() {
        ((ApparentModalI) this.caller).setNext(null);
    }

    @Override
    public void setNext(Frame w) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        RadioStationPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("RadioStationPU").createEntityManager();
        sexQuery = java.beans.Beans.isDesignTime() ? null : RadioStationPUEntityManager.createQuery("SELECT s FROM Sex s");
        sexList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : sexQuery.getResultList();
        musicgenreQuery = java.beans.Beans.isDesignTime() ? null : RadioStationPUEntityManager.createQuery("SELECT m FROM Musicgenre m");
        musicgenreList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : musicgenreQuery.getResultList();
        jPanel1 = new javax.swing.JPanel();
        birthPlaceJTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        kalOnomaJTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        birthdayJTextField = new javax.swing.JTextField();
        eponymoJTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        onomaJTextField = new javax.swing.JTextField();
        eponymoValidationJLabel = new javax.swing.JLabel();
        kalOnomaValidationJLabel = new javax.swing.JLabel();
        onomaValidationJLabel = new javax.swing.JLabel();
        sexJComboBox = new javax.swing.JComboBox();
        genreJComboBox = new javax.swing.JComboBox();
        birthPlaceValidationJLabel = new javax.swing.JLabel();
        birthdayValidationJLabel = new javax.swing.JLabel();
        actionJButton = new javax.swing.JButton();
        cancelJButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Διαχείριση καλλιτέχνη");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Στοιχεία καλλιτέχνη"));
        jPanel1.setToolTipText("");

        birthPlaceJTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                birthPlaceJTextFieldActionPerformed(evt);
            }
        });
        birthPlaceJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                birthPlaceJTextFieldKeyPressed(evt);
            }
        });

        jLabel1.setText("Επώνυμο");

        jLabel7.setText("Είδος μουσικής");
        jLabel7.setToolTipText("");

        jLabel2.setText("Όνομα");

        jLabel3.setText("Καλλιτεχνικό όνομα");

        kalOnomaJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                kalOnomaJTextFieldKeyPressed(evt);
            }
        });

        jLabel4.setText("Φύλο");

        jLabel5.setText("Ημ/νία γέννησης");

        birthdayJTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                birthdayJTextFieldActionPerformed(evt);
            }
        });
        birthdayJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                birthdayJTextFieldKeyPressed(evt);
            }
        });

        eponymoJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                eponymoJTextFieldKeyPressed(evt);
            }
        });

        jLabel6.setText("Τόπος γέννησης");

        onomaJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                onomaJTextFieldKeyPressed(evt);
            }
        });

        eponymoValidationJLabel.setText("(μέχρι 50 χαρακτήρες)");

        kalOnomaValidationJLabel.setText("(μέχρι 50 χαρακτήρες)");
        kalOnomaValidationJLabel.setToolTipText("");

        onomaValidationJLabel.setText("(μέχρι 50 χαρακτήρες)");
        onomaValidationJLabel.setToolTipText("");

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, sexList, sexJComboBox);
        bindingGroup.addBinding(jComboBoxBinding);

        sexJComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sexJComboBoxActionPerformed(evt);
            }
        });
        sexJComboBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                sexJComboBoxKeyPressed(evt);
            }
        });

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, musicgenreList, genreJComboBox);
        bindingGroup.addBinding(jComboBoxBinding);

        genreJComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                genreJComboBoxActionPerformed(evt);
            }
        });
        genreJComboBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                genreJComboBoxKeyPressed(evt);
            }
        });

        birthPlaceValidationJLabel.setText("(μέχρι 255 χαρακτήρες)");
        birthPlaceValidationJLabel.setToolTipText("");

        birthdayValidationJLabel.setText("πχ 23/9/2014 (4 ψηφία για το έτος)");
        birthdayValidationJLabel.setToolTipText("");
        birthdayValidationJLabel.setAutoscrolls(true);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(28, 28, 28))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(eponymoJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(eponymoValidationJLabel))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(onomaJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(onomaValidationJLabel))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(kalOnomaJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(kalOnomaValidationJLabel))
                    .addComponent(sexJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(birthdayJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(birthdayValidationJLabel))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(birthPlaceJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(birthPlaceValidationJLabel))
                    .addComponent(genreJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(eponymoJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(eponymoValidationJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(14, 14, 14)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(onomaJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(onomaValidationJLabel))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(kalOnomaJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(kalOnomaValidationJLabel)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addComponent(sexJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)))
                .addGap(15, 15, 15)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(birthdayJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(birthdayValidationJLabel))
                .addGap(15, 15, 15)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(birthPlaceJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(birthPlaceValidationJLabel)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(genreJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        actionJButton.setText("Αποθήκευση");
        actionJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionJButtonActionPerformed(evt);
            }
        });

        cancelJButton.setText("Ακύρωση");
        cancelJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(actionJButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cancelJButton))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(actionJButton)
                    .addComponent(cancelJButton))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void birthPlaceJTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_birthPlaceJTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_birthPlaceJTextFieldActionPerformed

    private void birthPlaceJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_birthPlaceJTextFieldKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.genreJComboBox.requestFocus();
        }
    }//GEN-LAST:event_birthPlaceJTextFieldKeyPressed

    private void kalOnomaJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_kalOnomaJTextFieldKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.sexJComboBox.requestFocus();
        }
    }//GEN-LAST:event_kalOnomaJTextFieldKeyPressed

    private void birthdayJTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_birthdayJTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_birthdayJTextFieldActionPerformed

    private void birthdayJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_birthdayJTextFieldKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.birthPlaceJTextField.requestFocus();
        }
    }//GEN-LAST:event_birthdayJTextFieldKeyPressed

    private void eponymoJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_eponymoJTextFieldKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.onomaJTextField.requestFocus();
        }
    }//GEN-LAST:event_eponymoJTextFieldKeyPressed

    private void onomaJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_onomaJTextFieldKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.kalOnomaJTextField.requestFocus();
        }
    }//GEN-LAST:event_onomaJTextFieldKeyPressed

    private void sexJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sexJComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sexJComboBoxActionPerformed

    private void sexJComboBoxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sexJComboBoxKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.birthdayJTextField.requestFocus();
        }
    }//GEN-LAST:event_sexJComboBoxKeyPressed

    private void genreJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genreJComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_genreJComboBoxActionPerformed

    private void genreJComboBoxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_genreJComboBoxKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.eponymoJTextField.requestFocus();
        }
    }//GEN-LAST:event_genreJComboBoxKeyPressed

    private void actionJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionJButtonActionPerformed
        try {
            if (this.actionType != General.ActionType.Delete) {
                //ελέγχει το input
                if (!General.checkJTFieldsInputVerification(this.jPanel1, this.getTitle(), this)) {
                    return;
                }
                //ελέγχει τα απαραίτητα πεδία
                try {
                    if (!General.checkNotNulls(new String[]{"Επώνυμο", "Όνομα", "Φύλο",
                        "Ημ/νία γέννησης", "Τόπος Γέννησης", "Είδος μουσικής"},
                            new JComponent[]{this.eponymoJTextField, this.onomaJTextField, this.sexJComboBox,
                                this.birthdayJTextField, this.birthPlaceJTextField, this.genreJComboBox}, this)) {
                        return;
                    }
                } catch (Exception ex) {
                    General.showErrorMessage(ex.getMessage(), "Error", this);
                    return;
                }
            }
            //Aνάλογα με περίπτωση διαχείρισης
            switch (this.actionType) {
                case Insert:
                    setEntiyFromFormData();
                    try {
                        General.insertToDB(this.artist, this.caller.getEM());
                    } catch (Exception ex) {
                        General.safeRollback(this.caller.getEM());
                        General.showDbErrorMsgIf(ex, this);
                        return;
                    }
                    this.caller.getEntityList().add(artist);
                    this.caller.enableDeleteUpdateIf();
                    int index = this.caller.getEntityList().indexOf(artist);
                    General.selectModelRowNVisible(index, this.caller.getTable());
                    break;
                case Update:
                    setEntiyFromFormData();
                    Artist a = null;
                    try {
                        a = this.caller.getEM().merge(this.artist);
                    } catch (Exception e) {
                        General.showErrorMessage(e.getMessage(), "Error", this);
                        return;
                    }
                    try {
                        General.updateDB(this.caller.getEM());
                        this.caller.getEntityList().set(General.getSelectedRowModelIndex(this.caller.getTable()), a);
                    } catch (Exception ex) {
                        General.safeRollback(this.caller.getEM());
                        if (a != null && !this.caller.getEM().contains(a)) {
                            a = this.caller.getEM().find(Artist.class, a.getArtistId());
                            if (a == null) {
                                General.showErrorMessage("Άγνωστο πρόβλημα με τη βάση δεδομένων.Η εφαρμογή θα κλείσει/n"
                                        + "προκειμένου να αποκλειστεί η πιθανότητα απώλειας ή αλλοίωσης δεδομένων", "Error", this);
                                System.exit(1);
                            }
                            int index2 = this.caller.getEntityList().indexOf(this.artist);
                            this.caller.getEntityList().set(index2, a);
                        }
                        General.showDbErrorMsgIf(ex, this);
                        return;
                    }
                    break;
                case Delete:
                    try {
                        General.deleteFromDB(this.artist.getArtistId(), this.artist, this.caller.getEM());
                        this.caller.disableDeleteUpdateIf();
                    } catch (Exception ex) {
                        General.safeRollback(this.caller.getEM());
                        General.showDbErrorMsgIf(ex, this);
                        return;
                    }
                    this.caller.getEntityList().remove(General.getSelectedRowModelIndex(this.caller.getTable()));
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            General.showErrorMessage(e.getMessage(), "Error", this);
        }
        this.caller.enableDeleteUpdateIf();
        this.caller.disableDeleteUpdateIf();
        General.closeWindowX(this);
    }//GEN-LAST:event_actionJButtonActionPerformed

    private void cancelJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelJButtonActionPerformed
        General.closeWindowX(this);
    }//GEN-LAST:event_cancelJButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DiaxeirishKallitexnwnJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DiaxeirishKallitexnwnJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DiaxeirishKallitexnwnJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DiaxeirishKallitexnwnJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DiaxeirishKallitexnwnJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager RadioStationPUEntityManager;
    private javax.swing.JButton actionJButton;
    private javax.swing.JTextField birthPlaceJTextField;
    private javax.swing.JLabel birthPlaceValidationJLabel;
    private javax.swing.JTextField birthdayJTextField;
    private javax.swing.JLabel birthdayValidationJLabel;
    private javax.swing.JButton cancelJButton;
    private javax.swing.JTextField eponymoJTextField;
    private javax.swing.JLabel eponymoValidationJLabel;
    private javax.swing.JComboBox genreJComboBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField kalOnomaJTextField;
    private javax.swing.JLabel kalOnomaValidationJLabel;
    private java.util.List<Model.Musicgenre> musicgenreList;
    private javax.persistence.Query musicgenreQuery;
    private javax.swing.JTextField onomaJTextField;
    private javax.swing.JLabel onomaValidationJLabel;
    private javax.swing.JComboBox sexJComboBox;
    private java.util.List<Model.Sex> sexList;
    private javax.persistence.Query sexQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
